
<?php
$auth = Auth::getAuth('current_user');
$db = new Database();
$user_id = $auth['id'];
$application_id = $_COOKIE['application'];
$applicationDoc = new Application($db, $application_id);
$strSqlGetEvents = "SELECT *,p.id as postID  FROM tbpost p
                LEFT JOIN tbuser u on p.postedBy=u.id
                WHERE p.is_active={$db->escape(1)}
                AND p.post_type={$db->escape(2)}
                AND (
                    CASE 
                    WHEN p.postPrivacyType = 1 THEN
                        EXISTS (SELECT * FROM (select g.id from tbgroups g WHERE g.id IN
                        (SELECT 
                         CASE 
                         WHEN FIND_IN_SET(u.id, g.Members)>0
                         THEN g.id
                         ELSE ''
                         END
                         FROM tbuser u WHERE u.id={$auth['id']})) A
                        WHERE A.id IN (SELECT 
                        CASE WHEN FIND_IN_SET(A.ID, p1.postPrivacyIDs)>0 THEN
                          A.id
                        ELSE 
                          ''
                        END               
                        FROM tbpost p1 WHERE p1.ID = p.id))
                    WHEN p.postPrivacyType = 2 THEN
                        FIND_IN_SET({$db->escape($auth['department_id'])},p.postPrivacyIDs)
                    WHEN p.postPrivacyType = 3 THEN
                        FIND_IN_SET({$db->escape($auth['position'])},p.postPrivacyIDs)
                    else
                        u.company_id={$db->escape($auth['company_id'])}
                   END
                    )
                OR p.is_active={$db->escape(1)}
				      AND p.post_type={$db->escape(2)}
                                    AND
                                    u.id = {$db->escape($auth['id'])} 
                ORDER BY p.id DESC";
// echo $strSqlGetEvents;
$getEvent = $db->query($strSqlGetEvents . " LIMIT 20", "array");
$countEvent = $db->query($strSqlGetEvents, "numrows");
?>
<Br/>
<script type="text/javascript" src="/js/functions/user_view/getData.js"></script>
<div class="dashboard_wrapper">
    <h1><?php echo $applicationDoc->category_name; ?> Dashboard</h1>
    <?php
    $dashboards = functions::getDashboards(" WHERE UserID = {$auth['id']} AND ApplicationID = {$application_id}");
    foreach ($dashboards as $dashboardDoc) {
        $dashboard_objects = json_decode($dashboardDoc->content, true);
    }

    $dashboard_objects = functions::my_array_unique($dashboard_objects);
    $widget_count = 0;
    foreach ($dashboard_objects as $dashboard_object_doc) {
        if ($dashboard_object_doc["object_type"] == 'request') {
            $form_id = $dashboard_object_doc["object_id"];

            $active_fields = functions::getFormFields($form_id);
            $forms = $db->query("SELECT * FROM tb_workspace WHERE id = {$db->escape($form_id)}", "row");
            $form_json = json_decode($forms['form_json']);
            $headerInfo = $form_json->{'form_json'}->{'collected_data_header_info'}->{'listedchoice'};
            $fields_headerObjType = $form_json->{'form_json'}->{'headerInfoType'};
            $activeFields = $forms['active_fields'];
            ?>
            <div class="fl-table-wrapper" fl-data="dashboard" fl-data-type="request" fl-data-object-id="<?php echo $form_id; ?>" fl-data-application-id="<?php echo $application_id; ?>" style="margin-bottom:110px" form_id="<?php echo $form_id; ?>">
                <div class="fl-option-toolbar">
                    <div class="fl-toolbar-left-wrapper">
                        <h3 style="line-height:30px"><?php echo $forms["form_name"]; ?></h3>
                    </div>
                    <div class="fl-toolbar-right-wrapper">
                        <a class="unpinit icon dataTip unpin" fl-data-application-id="1" fl-data-type="widget" fl-data-object-id="notif" data-placement="left" data-original-title="Unpin this from Dashboard"></a>
                        <a class="fl-drag icon dataTip handle_dashboard" data-placement="left" data-original-title="Drag Here"></a>
                    </div>
                    <div class="clearfix"></div>
                </div><!-- end of option toolbar -->
                <div class="form-informtion display">
                    <input type="text" class="display table-name" value="<?php echo $forms['form_table_name']; ?>">
                    <input type="text" class="display form-name" value="<?php echo $forms['form_name']; ?>">
                    <div class="activeFields"><?php echo $activeFields ?></div>
                    <div class="form-header "><?php echo json_encode($headerInfo); ?></div>
                    <div class="customColumnSettings "><?php echo json_encode($headerInfo); ?></div>
                    <input type="text" value="<?php echo $form_id; ?>" id="form_id" class="form_id">
                    <?php
                    $strSql = "SELECT DISTINCT COLUMN_NAME FROM information_schema.columns where table_name = '" . $forms['form_table_name'] . "' AND (DATA_TYPE = 'date' OR DATA_TYPE = 'datetime')";
                    $getdateFields = $db->query($strSql, "array");
                    $dateFields = array();
                    foreach ($getdateFields as $value) {
                        if (in_array($value['COLUMN_NAME'], $active_fields)) {
                            // echo $value['COLUMN_NAME'];
                            array_push($dateFields, $value['COLUMN_NAME']);
                        }
                    }
                    ?>
                    <select class="search-request-field_date display">
                        <?php
                        foreach ($dateFields as $value) {
                            echo "<option value='" . $value . "'>" . $value . "</option>";
                        }
                        ?>
                        <option value="DateCreated">DateCreated</option>
                    </select>
                </div>
                <TABLE class="fl-search-cont" BORDER="5" WIDTH="100%" CELLPADDING="4" CELLSPACING="0" border="2">
                    <TR ALIGN="CENTER">
                        <TD colspan="5" class="fl-header-tbl-wrapper">
                            <div class="fl-search-wrapper">
                                <!-- <form> -->
                                <input type="text"  placeholder="Search Requests" class="searchRequestUsersValue">
                                <input type="button" value="" class="search icon fl-btn-right searchRequestUsersButton" style="width:36px;position: relative; display:block;cursor:pointer">
                                <select class="fl-input-select search-request-field searchRequestUsersField display" style="margin-top:0px;width: 150px;margin-right:0px;padding-top: 5px;">
                                    <!-- <option value="0">All</option> -->
                                    <option value="TrackNo">Tracking Number</option>
                                    <option value="Requestor">Requestor</option>
                                    <option value="Processor">Processor</option>
                                    <option value="Status">Status</option>
                                    <?php
                                    foreach ($active_fields as $value) {
                                        echo "<option value='" . $value . "'>" . $value . "</option>";
                                    }
                                    ?>
                                </select>
                                <button class="tip btn-basicBtn padding_5 fl-basicsecondary-btn cursor fa fa-gear advanceFilterDialog" style="margin-left:4px; height: 31px;width: 30px;cursor:pointer" data-original-title="Advance Filter"></button>
                                <!-- <button class="tip btn-basicBtn padding_5 fl-basicsecondary-btn cursor fa fa-gear colSettings" style="margin-left:4px; height: 31px;width: 30px;cursor:pointer" data-original-title="Column Settings"></button> -->
                                <div class="fl-for-saving-fitler">
                                    <ul>
                                        <li class="display fl-buttonEffect filterAction fl-basicprimary-btn saveFC" id="saveFC">Save Filter</li>
                                        <li class="display filterAction fl-buttonEffect fl-basicprimary-btn cancelFC" id="cancelFC">Cancel</li>
                                        <div class="clearfix"></div>
                                    </ul>
                                <!-- <input type="button" value="Save Filter" class="display filterAction" id="saveFC" style="margin-left: 5px;">
                                <input type="button" value="Cancel" class="display filterAction" id="cancelFC"> -->
                                </div>
                                <!-- </form>   -->
                            </div>
                            <div class="fl-save-sort">
                                <select class="fl-input-select filterRequestsUser loadRF" style="width: 135px;">
                                    <option value="0" search_value="" search_field = "0">Filtered Request</option>
                                    <?php
                                    $strSql = "SELECT * FROM tbfilteredCategory WHERE user_id = '" . $user_id . "' && form_id = '" . $form_id . "'";
                                    $getSaveFilter = $db->query($strSql, "array");
                                    foreach ($getSaveFilter as $value) {
                                        echo '<option value="' . $value['id'] . '" '. "multi_search='". $value['multi_search'] ."'" .''. "multi_search='". $value['multi_search'] ."'" .' search_value="' . $value['search_value'] . '" search_field = "' . $value['search_field'] . '" date_field="' . $value['date_field'] . '" date_from="' . $value['date_from'] . '" date_to="' . $value['date_to'] . '">' . $value['title'] . '</option>';
                                    }
                                    ?>
                                </select>
                                <button class="tip btn-basicBtn padding_5 fl-basicsecondary-btn cursor requestFilterSettings fa fa-trash-o" style=" margin-left:1px; position:relative; top:-1px;height:31px;width: 30px;" data-original-title="Remove filter"></button>
                            </div> 
                        </TD>
                    </TR>
                </TABLE>
                <!-- Data table for request -->
                <?php
                $getCustomView = $db->query("SELECT * FROM tbcustomview WHERE user_id = $user_id AND form_id = $form_id ", "array");
                if (count($getCustomView) > 0) {
                    // $customView = json_decode($getCustomView[0]['json'], true);
                    $customView = getValidHeaderFields($headerInfo,$getCustomView,$fields_headerObjType);
                } else {

                    // for default view
                    $customView = array(array("field_label" => "Tracking Number", "field_name" => "TrackNo"), array("field_label" => "Requestor", "field_name" => "requestorName"), array("field_label" => "Status", "field_name" => "Status"), array("field_label" => "Date Created", "field_name" => "DateCreated"));
                    // push to array in specific location
                    $otherFieldsStartPos = 2;
                    $fields_headerObj = $headerInfo;
                    foreach ($fields_headerObj as $fields_header) {
                        array_insert($customView, array("field_label" => "" . $fields_header->{'field_label'} . "", "field_name" => "" . $fields_header->{'field_name'} . ""), $otherFieldsStartPos);
                        $otherFieldsStartPos++;
                    }
                    //Updated by AARON TOLENTINO
                    // - For having a specific and default header information


                    if($fields_headerObjType=="1"){

                        $customView = array();
                        foreach ($fields_headerObj as $fields_header) {
                            array_push($customView, array("field_label" => "" . $fields_header->{'field_label'} . "", "field_name" => "" . $fields_header->{'field_name'} . ""));
                        }
                    }else if($fields_headerObjType=="0"){
                        // FOR DEFAULT COLUMN
                        $customView = array(array("field_label" => "Tracking Number", "field_name" => "TrackNo"), array("field_label" => "Requestor", "field_name" => "requestorName"), array("field_label" => "Status", "field_name" => "Status"), array("field_label" => "Date Created", "field_name" => "DateCreated"));
                    }
                    $customView = json_decode(json_encode($customView), true);
                    // print_r($customView);
                }
                ?>
                <!-- OLD CHECKBOX FOR HOME <input type='checkbox' class='checkAllAction' /> -->
                <div class="fl-datatable-wrapper" style="width:100%; overflow:auto; overflow-y:hidden;">
                    <table class="display_data dataTable recordsDatatable"  id="loadFormRecords<?php echo $form_id; ?>" style="">
                        <thead class="fl-header-tbl-wrapper">
                            <tr>
                                <?php
                                echo "<th style='width:80px!important;'>" . "<div class='fl-table-ellip' style=''><input type='checkbox' name='checkboxG4' id='checkboxG4' class='css-checkbox checkAllAction' /><label for='checkboxG4' class='css-label'></label>
                                    </div></th>";
                                $width = "";
                                foreach ($customView as $value) {
                                    if ($value['field_name'] != "") {
                                        if ($value['width'] != "") {
                                            $width = "width:" . $value['width'] . ";";
                                        }
                                        echo "<th style='" . $width . "' field_name='" . $value['field_name'] . "'>" . "<span class='sortable-image' style='position:absolute'></span><div class='fl-table-ellip'>" . $value['field_label'] . "</th>";
                                    }
                                }
                                ?>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>

                </div>
                <div class="dataTable_widget"></div>
            </div>
            <br/>
            <br/>

            <!-- end of table-->
            <?php
        }


        if ($dashboard_object_doc["object_type"] == 'report') {
            ?>
            <div class="fl-table-wrapper" style="margin-bottom:73px; margin-top:10px;" fl-data="dashboard" fl-data-application-id="<?php echo $application_id; ?>" fl-data-type="report" fl-data-object-id="<?php echo $dashboard_object_doc["object_id"]; ?>" fl-data-url="<?php echo $dashboard_object_doc["url"]; ?>" fl-data-report-id="<?php echo $dashboard_object_doc["reportId"] ?>" fl-data-form-id="<?php echo $dashboard_object_doc["formId"] ?>">
                <div class="fl-widget-head">
                    <div class="widget-icon-wrapper">
                        <span class="reports icon"></span><span class="widget-title"><?php echo $dashboard_object_doc["object_id"]; ?></span>
                        <div class="fl-toolbar-right-wrapper">
                            <a class="icon dataTip unpin" style="background-position:-41px -525px;" fl-data-application-id="1" fl-data-type="widget" fl-data-object-id="notif" data-placement="left" data-original-title="Unpin this from Dashboard"></a>
                            <a class="fl-drag icon dataTip handle_dashboard" style="background-position: -43px -560px;"  data-placement="left" data-original-title="Drag Here"></a>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="fl-report-wrapper-content" fl-data-report-id="<?php echo $dashboard_object_doc["reportId"] ?>" fl-data-form-id="<?php echo $dashboard_object_doc["formId"] ?>">
                    <div align="center" style="width:100%;height: 400px">
                        <iframe style="width:100%;height: 400px" src="<?php echo $dashboard_object_doc["url"]; ?>">
                        <p>Your browser does not support iframes.</p>
                        </iframe>
                    </div>
                </div>
            </div>  
            <?php
        }

        if ($dashboard_object_doc["object_type"] == 'request_form') {
            ?>
            <div class="fl-table-wrapper" style="margin-bottom:73px; margin-top:10px;" fl-data="dashboard" fl-data-application-id="<?php echo $application_id; ?>" fl-data-type="request_form" fl-data-object-id="<?php echo $dashboard_object_doc["object_id"]; ?>" fl-data-url="<?php echo $dashboard_object_doc["url"]; ?>" fl-data-form-id="<?php echo $dashboard_object_doc["formId"] ?>" fl-data-request-id="<?php echo $dashboard_object_doc["requestId"] ?>">
                <div class="fl-widget-head">
                    <div class="widget-icon-wrapper">
                        <span class="modules icon" style="background-position:-3px -103px;"></span><span class="widget-title"><?php echo $dashboard_object_doc["object_id"]; ?></span>
                        <div class="fl-toolbar-right-wrapper">
                            <a class="icon dataTip unpin" style="background-position:-41px -526px;" fl-data-application-id="1" fl-data-type="widget" fl-data-object-id="notif" data-placement="left" data-original-title="Unpin this from Dashboard"></a>
                            <a class="fl-drag icon dataTip handle_dashboard" style="background-position: -43px -560px;"  data-placement="left" data-original-title="Drag Here"></a>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="fl-report-wrapper-content" fl-data-form-id="<?php echo $dashboard_object_doc["formId"] ?>" fl-data-request-id="<?php echo $dashboard_object_doc["requestId"] ?>">
                    <div align="center" style="width:100%;height: 400px">
                        <iframe style="width:100%;height: 400px" src="<?php echo $dashboard_object_doc["url"]; ?>">
                        <p>Your browser does not support iframes.</p>
                        </iframe>
                    </div>
                </div>
            </div>  
            <?php
        }
        if ($dashboard_object_doc["object_type"] == 'widget') {
            ?>
            <!--    <Br/><Br/><Br/><Br/> -->
            <div class="fl-table-wrapper fl-widgets-wrapper"  fl-data="dashboard" fl-data-application-id="<?php echo $application_id; ?>" fl-data-type="widget" fl-data-object-id="widget">
                <div class="fl-widget-head">
                    <div class="widget-icon-wrapper">
                        <span class="widget-title">Widgets</span>
                        <div class="fl-toolbar-right-wrapper">
                            <a class="fl-drag icon dataTip handle_dashboard"   data-placement="left" data-original-title="Drag Here" style="background-position: -40px -559px;"></a>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="section group">
                    <div class="col fl-widget">
                        <div class="fl-widget-head">
                            <div class="widget-icon-wrapper">
                                <span class="company-events icon"></span><span class="widget-title">Company Events<a href="#"><strong class="counter fl-counter-dashboard"><?php echo $countEvent; ?></strong></a></span>

                            </div>
                        </div>
                        <div class="fl-widget-wrapper eventsUserWidgetWrapper" style="overflow:hidden;position: relative;">
                            <div class="fl-events-container-users eventsUserWidget" style="height:auto;">
                                <!--
                                <?php
                                //foreach ($getEvent as $event) {
                                //    $link = functions::curPageURL('port') ."/post?view_type=view_post&postID=" . functions::base_encode_decode("encrypt", $event['postID']);
                                //    echo '<a href="' . $link . '" class="cursor dataTip" data-original-title="Show link">';
                                ?>
                                    <div class="fl-widget-info">
                                    <div class="fl-widget-content" style="overflow:hidden;position: relative;">
                                        <div class="fl-avatar">
                                <?php
                                //echo userQueries::avatarPic("tbuser", $event['postedBy'], "30", "30", "small", "avatar");
                                ?>
                                        </div>
                                        <div class="fl-widget-cpnyevnts-content-wrapper theme-font-color">
                                <?php
                                //$post_event = $event['post'];
                                //echo substr(str_replace("&lt;br&gt;", "\n", $post_event), 0, 40);
                                //echo htmlspecialchars_decode(functions::truncate($event['post'], 40));
                                ?>                      
                                        </div>
                                        <div class="clearfix"></div>
                                    </div>
                                    <span class="time" style="margin:-3% 2% 1% 1%;">Posted <label class="timeago" title="<?php echo $event['date_posted']; ?>">about <?php echo $event['date_posted']; ?></label></span>
                                    <div class="clearfix"></div>
                                </div>
                                <?php
                                //}
                                ?>
                                -->
                            </div>
                            <!-- all about loading -->
                            <div class="fl-see-all display seeAllEvent">
                                <a href="<?php echo USER_VIEW . 'company_events'; ?>"><span>See all <i class="fa fa-hand-o-right"></i></span></a>
                            </div> 
                            <div class="fl-widget-wrapper-center-content display load_pevent">
                                <!-- for loading congtent -->
                                <div class="fl-loading-content">
                                    <div align="center"><img src="/images/icon/loading.gif"></div>
                                    <p>Loading Content...</p>
                                </div> 
                                <!-- for loading congtent -->
                                <!-- for no data -->
                                <!--<div class="fl-no-data-found">
                                    <span><i class="fa fa-files-o"></i> No Data Found.</span>
                                 </div> -->
                                <!-- for no data -->
                            </div>
                            <!-- all about loading --> 
                        </div>
                    </div><!-- end of company events -->


                    <div class="col fl-widget">
                        <div class="fl-widget-head">
                            <div class="widget-icon-wrapper">
                                <span class="my-requests icon"></span><span class="widget-title">My Requests<a href="#"><!-- <strong class="counter my_request_count fl-counter-dashboard">20</strong> --></a></span>
                            </div>
                        </div>
                        <div class="fl-widget-wrapper myRequestUserWidgetWrapper" style="overflow:hidden;position: relative;">
                            <div class="fl-myrequest-container-users myRequestUserWidget" style="height:auto;">
                                <!-- <div class="fl-widget-content">
                                   <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                   <div class="fl-widget-my-requests-content-wrapper">
                                    <span>Request:</span> <span class="request-data theme-font-color"><a href="#">Discussion</a></span><br/>
                                     <span>Request ID:</span> <span class="request-data theme-font-color">dis0115</span><br/>
                                     <span>Request Status:</span> <span class="request-data request-status theme-font-color">Active</span> </div>
                                  <span class="request-time">2014-01-02 09:20:11</span>   
                                   <div class="clearfix"></div>
                                   <div align="center"><img src="images/icon/loading.gif"></div>
                                </div>
                                <div class="fl-widget-content">
                                   <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                   <div class="fl-widget-my-requests-content-wrapper">
                                    <span>Request:</span> <span class="request-data theme-font-color">Discussion</span><br/>
                                     <span>Request ID:</span> <span class="request-data theme-font-color">dis0115</span><br/>
                                     <span>Request Status:</span> <span class="request-data request-status theme-font-color">Active</span> </div>
                                   <span class="request-time">2014-01-02 09:20:11</span>   
                                   <div class="clearfix"></div>
                                </div> -->
                            </div>
                            <!-- all about loading -->
                            <!-- <div class="fl-see-all">
                              <a href="/user_view/my-requests"><span>See all <i class="fa fa-hand-o-right"></i></span></a>
                            </div>  -->
                            <div class="fl-widget-wrapper-center-content display">
                                <!-- for loading congtent -->
                                <div class="fl-loading-content display">
                                    <div align="center"><img src="/images/icon/loading.gif"></div>
                                    <p>Loading Content...</p>
                                </div>
                                <!-- for loading congtent -->
                                <!-- for no data -->
                                <div class="fl-no-data-found display">
                                    <span><i class="fa fa-files-o"></i> No Data Found.</span>
                                </div>
                                <!-- for no data -->
                            </div>
                            <!-- all about loading --> 
                        </div>
                    </div>  <!-- end of request -->


                    <div class="col fl-widget">
                        <div class="fl-widget-head">
                            <div class="widget-icon-wrapper">
                                <span class="starred icon"></span><span class="widget-title">Starred<a href="#"><strong class="counter starred_count fl-counter-dashboard" >50</strong></a></span>
                            </div>
                        </div>
                        <div class="fl-widget-wrapper starredUserWidgetWrapper" style="overflow:hidden;position: relative;">
                            <div class="fl-starred-container-users starredUserWidget" style="height:auto;">
                                <!-- <div class="fl-widget-content">
                                    <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                    <div class="fl-widget-starred-content-wrapper">
                                      <span class="fl-delete">x</span>
                                      <span class="starredtype-data theme-font-color">Announcement</span><br/>
                                      <span class="starredname-data">Bruce Lee</span><br/>
                                      <span class="starreddate-data">2014-01-02 09:20:11</span>
                                    </div>
                                    <div class="clearfix"></div>
                                 </div>
                                 <div class="fl-widget-content">
                                    <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                    <div class="fl-widget-starred-content-wrapper">
                                      <span class="fl-delete">x</span>
                                      <span class="starredtype-data theme-font-color">Announcement</span><br/>
                                      <span class="starredname-data">Bruce Lee</span><br/>
                                      <span class="starreddate-data">2014-01-02 09:20:11</span>
                                    </div>
                                    <div class="clearfix"></div>
                                 </div>
                                 <div class="fl-widget-content">
                                    <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                    <div class="fl-widget-starred-content-wrapper">
                                      <span class="fl-delete">x</span>
                                      <span class="starredtype-data theme-font-color">Announcement</span><br/>
                                      <span class="starredname-data">Bruce Lee</span><br/>
                                      <span class="starreddate-data">2014-01-02 09:20:11</span>
                                    </div>
                                    <div class="clearfix"></div>
                                 </div> -->
                            </div>
                            <!-- all about loading -->
                            <div class="fl-widget-wrapper-center-content display">
                                <!-- for loading congtent -->
                                <div class="fl-loading-content display">
                                    <div align="center"><img src="/images/icon/loading.gif"></div>
                                    <p>Loading Content...</p>
                                </div>
                                <!-- for loading congtent -->
                                <!-- for no data -->
                                <div class="fl-no-data-found display">
                                    <span><i class="fa fa-files-o"></i> No Data Found.</span>
                                </div>
                                <!-- for no data -->
                            </div> 
                            <!-- all about loading --> 
                        </div>  
                    </div>  
                </div><!-- end of starred -->

                <div class="section group">
                    <div class="col fl-widget">
                        <div class="fl-widget-head">
                            <div class="widget-icon-wrapper">
                                <?php
                                $userCompany = new userQueries();
                                $usersOnline = $userCompany->onlineUser($auth['company_id'], $auth['id']);
                                ?>
                                <span class="online-user icon"></span><span class="widget-title">Online Users  <strong class="counter countUOnline fl-counter-dashboard">
                                        <?php echo $usersOnline[0]['countUserOnline']; ?></strong></a>
                                    </strong></span>

                            </div>
                        </div>
                        <div class="fl-online-user-wrapper">
                            <div class="fl-widget-content onlineUsers">
                                <div id="online-users-container" 
                                     class="online onlineUsers" 
                                     data-socket-active="<?php echo SOCKET_ACTIVE ?>" 
                                     data-socket-server="<?php echo SOCKET_SERVER; ?>"
                                     >
                                         <?php
                                         if ($usersOnline[0]['countUserOnline'] == "0") {
                                             echo "<b>No Users Online.</b>";
                                         } else {
                                             echo $usersOnline[0]['images'];
                                         }
                                         ?>
                                </div>
                            </div>               
                        </div>
                    </div><!-- end of company events --> 

                </div>
            </div>
            <?php
        }
    }

    if (count($dashboards) == 0) {
        //no existing dashboard
        ?>
        <div class="fl-table-wrapper"  fl-data="dashboard" fl-data-application-id="<?php echo $application_id; ?>" fl-data-type="widget" fl-data-object-id="widget">
            <div class="section group">
                <div class="col fl-widget">
                    <div class="fl-widget-head">
                        <div class="widget-icon-wrapper">
                            <span class="company-events icon"></span><span class="widget-title">Company Events<a href="#"><strong class="counter fl-counter-dashboard"><?php echo $countEvent; ?></strong></a></span>

                        </div>
                    </div>
                    <div class="fl-widget-wrapper eventsUserWidgetWrapper" style="overflow:hidden;position: relative;">
                        <div class="fl-events-container-users eventsUserWidget" style="height:auto;">
                            <?php
                            foreach ($getEvent as $event) {
                                $link = functions::curPageURL('port') . "/post?view_type=view_post&postID=" . functions::base_encode_decode("encrypt", $event['postID']);
                                echo '<a href="' . $link . '" class="cursor dataTip" data-original-title="Show link">';
                                ?>
                                <div class="fl-widget-content" style="overflow:hidden;position: relative;">
                                    <div class="fl-avatar">
                                        <?php
                                        echo userQueries::avatarPic("tbuser", $event['postedBy'], "30", "30", "small", "avatar");
                                        ?>
                                    </div>
                                    <div class="fl-widget-cpnyevnts-content-wrapper theme-font-color">
                                        <?php
                                        $post_event = $event['post'];
                                        echo substr(str_replace("&lt;br&gt;", "\n", $post_event), 0, 40);
                                        //echo htmlspecialchars_decode(functions::truncate($event['post'], 40));
                                        ?>                      
                                    </div>
                                    <span class="time">Posted <label class="timeago" title="<?php echo $event['date_posted']; ?>">about <?php echo $event['date_posted']; ?></label></span><!--company events time ago-->
                                    <div class="clearfix"></div>
                                </div>
                                <?php
                            }
                            ?>
                        </div>
                        <!-- all about loading -->
                        <div class="fl-see-all">
                            <a href="#"><span>See all <i class="fa fa-hand-o-right"></i></span></a>
                        </div> 
                        <div class="fl-widget-wrapper-center-content">
                            <!-- for loading congtent -->
                            <!--  <div class="fl-loading-content">
                               <div align="center"><img src="/images/icon/loading.gif"></div>
                               <p>Loading Content...</p>
                             </div> -->
                            <!-- for loading congtent -->
                            <!-- for no data -->
                            <!--  <div class="fl-no-data-found">
                                <span><i class="fa fa-files-o"></i> No Data Found.</span>
                             </div> -->
                            <!-- for no data -->
                        </div>
                        <!-- all about loading --> 
                    </div>
                </div><!-- end of company events -->


                <div class="col fl-widget">
                    <div class="fl-widget-head">
                        <div class="widget-icon-wrapper">
                            <span class="my-requests icon"></span><span class="widget-title">My Requests<a href="#"><!-- <strong class="counter my_request_count fl-counter-dashboard">20</strong> --></a></span>
                        </div>
                    </div>
                    <div class="fl-widget-wrapper myRequestUserWidgetWrapper" style="overflow:hidden;position: relative;">
                        <div class="fl-myrequest-container-users myRequestUserWidget" style="height:auto;">
                            <!-- <div class="fl-widget-content">
                               <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                               <div class="fl-widget-my-requests-content-wrapper">
                                <span>Request:</span> <span class="request-data theme-font-color"><a href="#">Discussion</a></span><br/>
                                 <span>Request ID:</span> <span class="request-data theme-font-color">dis0115</span><br/>
                                 <span>Request Status:</span> <span class="request-data request-status theme-font-color">Active</span> </div>
                              <span class="request-time">2014-01-02 09:20:11</span>   
                               <div class="clearfix"></div>
                               <div align="center"><img src="images/icon/loading.gif"></div>
                            </div>
                            <div class="fl-widget-content">
                               <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                               <div class="fl-widget-my-requests-content-wrapper">
                                <span>Request:</span> <span class="request-data theme-font-color">Discussion</span><br/>
                                 <span>Request ID:</span> <span class="request-data theme-font-color">dis0115</span><br/>
                                 <span>Request Status:</span> <span class="request-data request-status theme-font-color">Active</span> </div>
                               <span class="request-time">2014-01-02 09:20:11</span>   
                               <div class="clearfix"></div>
                            </div> -->
                        </div>
                        <!-- all about loading -->
                        <!-- <div class="fl-see-all">
                          <a href="/user_view/my-requests"><span>See all <i class="fa fa-hand-o-right"></i></span></a>
                        </div>  -->
                        <div class="fl-widget-wrapper-center-content">
                            <!-- for loading congtent -->
                            <div class="fl-loading-content display">
                                <div align="center"><img src="/images/icon/loading.gif"></div>
                                <p>Loading Content...</p>
                            </div>
                            <!-- for loading congtent -->
                            <!-- for no data -->
                            <div class="fl-no-data-found display">
                                <span><i class="fa fa-files-o"></i> No Data Found.</span>
                            </div>
                            <!-- for no data -->
                        </div>
                        <!-- all about loading --> 
                    </div>
                </div>  <!-- end of request -->


                <div class="col fl-widget">
                    <div class="fl-widget-head">
                        <div class="widget-icon-wrapper">
                            <span class="starred icon"></span><span class="widget-title">Starred<a href="#"><strong class="counter starred_count fl-counter-dashboard" >50</strong></a></span>
                        </div>
                    </div>
                    <div class="fl-widget-wrapper starredUserWidgetWrapper" style="overflow:hidden;position: relative;">
                        <div class="fl-starred-container-users starredUserWidget" style="height:auto;">
                            <!-- <div class="fl-widget-content">
                                <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                <div class="fl-widget-starred-content-wrapper">
                                  <span class="fl-delete">x</span>
                                  <span class="starredtype-data theme-font-color">Announcement</span><br/>
                                  <span class="starredname-data">Bruce Lee</span><br/>
                                  <span class="starreddate-data">2014-01-02 09:20:11</span>
                                </div>
                                <div class="clearfix"></div>
                             </div>
                             <div class="fl-widget-content">
                                <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                <div class="fl-widget-starred-content-wrapper">
                                  <span class="fl-delete">x</span>
                                  <span class="starredtype-data theme-font-color">Announcement</span><br/>
                                  <span class="starredname-data">Bruce Lee</span><br/>
                                  <span class="starreddate-data">2014-01-02 09:20:11</span>
                                </div>
                                <div class="clearfix"></div>
                             </div>
                             <div class="fl-widget-content">
                                <div class="fl-avatar"><img src="images/avatar/avatar.png"></div>
                                <div class="fl-widget-starred-content-wrapper">
                                  <span class="fl-delete">x</span>
                                  <span class="starredtype-data theme-font-color">Announcement</span><br/>
                                  <span class="starredname-data">Bruce Lee</span><br/>
                                  <span class="starreddate-data">2014-01-02 09:20:11</span>
                                </div>
                                <div class="clearfix"></div>
                             </div> -->
                        </div>
                        <!-- all about loading -->
                        <div class="fl-widget-wrapper-center-content">
                            <!-- for loading congtent -->
                            <div class="fl-loading-content display">
                                <div align="center"><img src="/images/icon/loading.gif"></div>
                                <p>Loading Content...</p>
                            </div>
                            <!-- for loading congtent -->
                            <!-- for no data -->
                            <div class="fl-no-data-found display">
                                <span><i class="fa fa-files-o"></i> No Data Found.</span>
                            </div>
                            <!-- for no data -->
                        </div> 
                        <!-- all about loading --> 
                    </div>  
                </div>  
            </div><!-- end of starred -->

            <div class="section group">
                <div class="col fl-widget">
                    <div class="fl-widget-head">
                        <div class="widget-icon-wrapper">
                            <?php
                            $userCompany = new userQueries();
                            $usersOnline = $userCompany->onlineUser($auth['company_id'], $auth['id']);
                            ?>
                            <span class="online-user icon"></span><span class="widget-title">Online Users  <strong class="counter countUOnline fl-counter-dashboard">
                                    <?php echo $usersOnline[0]['countUserOnline']; ?></strong></a>
                                </strong></span>

                        </div>
                    </div>
                    <div class="fl-online-user-wrapper">
                        <div class="fl-widget-content onlineUsers">
                            <div id="online-users-container" 
                                 class="online onlineUsers" 
                                 data-socket-active="<?php echo SOCKET_ACTIVE ?>" 
                                 data-socket-server="<?php echo SOCKET_SERVER; ?>"
                                 >
                                     <?php
                                     if ($usersOnline[0]['countUserOnline'] == "0") {
                                         echo "<b>No Users Online.</b>";
                                     } else {
                                         echo $usersOnline[0]['images'];
                                     }
                                     ?>
                            </div>
                        </div>               
                    </div>
                </div><!-- end of company events --> 

            </div>
        </div>
        <?php
    }
    ?>

</DIV>